<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="项目名称" prop="extractItem">
        <el-input
          v-model="queryParams.extractItem"
          placeholder="请输入项目名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="抽取人单位" prop="createBy">
        <el-select
          v-model="queryParams.createBy"
          placeholder="请选择抽取人单位"
          clearable
          size="small"
          style="width: 100%"
          @change="UnitTypeChangepenson"
        >
          <el-option
            v-for="type in unitTypeponsonOptions"
            :key="type.userId"
            :label="type.nickName"
            :value="type.userId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="抽取库" prop="randomUnittypeId">
        <el-select
          v-model="queryParams.randomUnittypeId"
          placeholder="请选择单位库"
          clearable
          size="small"
          style="width: 100%"
          @change="UnitTypeChange"
        >
          <el-option
            v-for="type in unitTypeOptions"
            :key="type.unittypeId"
            :label="type.unittypeName"
            :value="type.unittypeId"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="extractList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="项目名称"
        align="left"
        prop="extractItem"
        width="350"
      />
      <el-table-column
        label="业务类型"
        align="left"
        prop="extractBusinessType"
        width="150"
      />
      <!-- <el-table-column label="建设地址" align="left" prop="extractAddress" /> -->
      <el-table-column
        label="抽取人单位"
        align="left"
        prop="createBy"
        width="200"
      />
      <el-table-column
        label="工程费用（万元）"
        align="left"
        prop="extractPrice"
      />
      <el-table-column
        label="中介机构服务费（万元）"
        align="left"
        prop="maxPrice"
      />
      <el-table-column
        label="抽取库"
        align="left"
        width="200"
        prop="unitTypeName"
      />
      <el-table-column
        label="审批状态"
        align="center"
        prop="extractApproveStatus"
        :formatter="approveStatusFormat"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['unit:extract:edit']"
            >审批</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目申请对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1200px"
      append-to-body
      :close-on-click-modal="false"
      @close="cancelImg"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <div class="topbox">
          <el-row
            :gutter="15"
            style="
              margin-top: -30px;
              margin-bottom: -30px;
              padding-bottom: -60px;
            "
          >
            <el-col :span="12">
              <el-form-item label="申请单位:" prop="createBy">{{
                form.createBy
              }}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目名称:" prop="extractItem">{{
                form.extractItem
              }}</el-form-item>
            </el-col>
          </el-row>
          <el-row
            :gutter="15"
            style="
              margin-top: -60px;
              margin-bottom: -60px;
              padding-bottom: -60px;
            "
            v-if="unittype!='15'"
          >
            <el-col :span="12">
              <el-form-item label="建设地址:" prop="extractAddress">{{
                form.extractAddress
              }}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="建设周期:" prop="extractPeriod">{{
                form.extractPeriod
              }}</el-form-item>
            </el-col>
          </el-row>
          <el-row
            :gutter="15"
            style="
              margin-top: -30px;
              margin-bottom: -60px;
              padding-bottom: -60px;
            "
          >
            <el-col :span="12">
              <el-form-item label="工程费用(万元):" prop="extractPrice">{{
                form.extractPrice
              }}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="抽取要求:" prop="extractBanReason">{{
                form.extractBanReason
              }}</el-form-item>
            </el-col>
          </el-row>
        </div>
        <div class="btobox">
          <el-row :gutter="15" v-if="unittype!='15'">
            <el-col :span="12">
              <el-form-item label="中介机构服务费（万元）:" prop="maxPrice">{{
                form.maxPrice
              }}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="工程概况:" prop="projectOverview">{{
                form.projectOverview
              }}</el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="15">
            <el-col :span="12">
              <el-form-item label="经办人:" prop="extractCharge">{{
                form.extractCharge
              }}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系电话:" prop="extractPhone">{{
                form.extractPhone
              }}</el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="15"> </el-row>
          <el-row :gutter="15">
            <el-col :span="12">
              <el-form-item label="业务类型:">{{
                form.extractBusinessType
              }}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="签字表:">
                <el-image
                  style="width: 100px; height: 100px"
                  :src="form.extractSignUrl"
                  :preview-src-list="imgUrl"
                  :z-index="3000"
                  v-if="
                    this.form.extractSignUrl != null &&
                    this.form.extractSignUrl != undefined &&
                    this.form.extractSignUrl != ''
                  "
                >
                </el-image>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="15" v-if="unittype!='15'">
            <el-col :span="12">
              <el-form-item label="是否驻场服务:">{{
                form.extractResident == 0 ? "是" : "否"
              }}</el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="15" v-if="form.extractResident == 0">
            <el-col :span="12">
              <el-form-item label="驻场服务人数:">{{
                form.extractResidentNumber
              }}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="完成时限:">{{
                form.extractLimitedTime
              }}</el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="15" v-if="form.extractResident == 0">
            <el-col :span="12">
              <el-form-item label="驻场要求:">{{
                form.extractStationRequire
              }}</el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="15" v-if="unittype!='15'">
            <el-col :span="12">
              <el-form-item label="抽取单位数:">{{
                form.extractNumber
              }}</el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="15" v-else>
            <el-col :span="12">
              <el-form-item label="抽取人数:">{{
                form.extractNumber
              }}</el-form-item>
            </el-col>
          </el-row>
        </div>
        <el-form-item label="抽取库:" prop="randomUnittypeId">
          <el-button type="text" @click="viewUnits">{{ unitName }}</el-button>
        </el-form-item>
        <!-- 库下对应单位表格 -->
        <el-dialog 
          :title="unitName"
          :visible.sync="unitsVisible" 
          append-to-body
          width="1080px"
        >
          <el-row v-if="unittype!='15'">
            <el-table
              v-loading="loading"
              id="unitTable"
              :data="unitList"
              :row-class-name="tableRowClassName"
              :row-style="rowStyle"
            >
              <el-table-column
                label="序号"
                align="center"
                prop="unitSort"
                width="100"
              />
              <el-table-column
                label="单位名称"
                align="left"
                prop="unitName"
                width="310"
              />
              <el-table-column
                label="资质"
                align="center"
                prop="unitNaturalGrade"
                width="150"
                v-if="showmake"
              />
              <!-- <el-table-column label="手动排除" align="center" prop="extractPrice" :formatter="ManualApproveStatusFormat" width="120"/> -->
              <el-table-column
                label="是否选择"
                align="center"
                prop="isTick"
                width="120"
              >
                <template slot-scope="scope">
                  {{scope.row.isTick == 1 ? "是" : "否"}}
                </template>
              </el-table-column>
              <el-table-column
                label="操作"
                align="center"
                class-name="small-padding fixed-width"
              >
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-edit"
                    @click="unitShow(scope.row)"
                    v-hasPermi="['unit:extract:edit']"
                    >单位详情</el-button
                  >
                  <!-- <el-button size="mini" type="text" icon="el-icon-circle-close" @click="overcome(scope.row)" v-if="scope.row.unitStatues == 0">排除</el-button>
                  <el-button size="mini" type="text" icon="el-icon-refresh-right" @click="DeleteMappingBtn(scope.row)" v-if="scope.row.unitStatues == 1">
                    还原
                  </el-button> -->
                </template>
              </el-table-column>
            </el-table>
          </el-row>
          <el-row v-else>
            <el-table
              v-loading="loading"
              id="unitTable"
              :data="agentlist"
              max-height="400"
              :row-style="rowStyle"
            >
              <el-table-column
                label="编号"
                align="center"
                prop="agentid"
                width="100"
              />
              <el-table-column
                label="招标人代表姓名"
                align="center"
                prop="name"
                width="210"
              />
              <el-table-column
                label="专业"
                align="left"
                prop="speciality"
                width="300"
              />
              <el-table-column
                label="类别"
                align="center"
                prop="professionType"
                width="200"
              />
              <el-table-column
                label="是否选择"
                align="center"
                prop="isTick"
                width="150"
              >
                <template slot-scope="scope">
                  {{ scope.row.isTick == 1 ? "是" : "否" }}
                </template>
              </el-table-column>
            </el-table>
          </el-row>
        </el-dialog>
        <h3>审批意见</h3>
        <el-form-item label="审批结果">
          <el-radio v-model="radio" label="0">同意</el-radio>
          <el-radio v-model="radio" label="1">拒绝</el-radio>
        </el-form-item>
        <el-form-item label="短信结束时间" v-if="form.unitTypeId == 11">
          <div class="block">
            <el-date-picker
              v-model="dateTime"
              type="datetime"
              placeholder="选择日期时间"
              :default-time="`${hour}:${minute + 30}:00`"
              format="yyyy-MM-dd HH:mm"
              value-format="yyyy-MM-dd HH:mm"
            >
            </el-date-picker>
          </div>
        </el-form-item>
        <el-form-item label="审批结果"
          ><el-input
            v-model="form.extractApproveIdea"
            type="textarea"
            placeholder="请输入内容"
        /></el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 单位信息对话框 -->
    <!-- <el-dialog
      :title="title"
      :visible.sync="unitopen"
      width="60%"
      append-to-body
      :close-on-click-modal="false"
    >
      <div class="unitSort-box">
        <unitDetail :formUnit="formUnit"></unitDetail>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormUnit">确 定</el-button>
      </div>
    </el-dialog> -->
    <DetailDialog :visible.sync="unitopen" :formUnit="formUnit" />
    <el-dialog
      :title="title"
      :visible.sync="exclude"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="排除理由" prop="maxPrice">
          <el-input
            v-model="form.randomBanRansom"
            type="textarea"
            cols="5"
            rows="5"
            placeholder="请输入排除理由"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="excludeSave">保 存</el-button>
        <el-button @click="call">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 排除理由查看框    placeholder="请输入排除理由" type="textarea" cols="5" rows="5" -->
    <el-dialog
      :title="title1"
      :visible.sync="outframe"
      width="700px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px"
        ><el-input
          v-model="form.randomBanRansom"
          type="textarea"
          cols="10"
          rows="10"
      /></el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="determined">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listExtractPage,
  getExtract,
  delExtract,
  addExtract,
  exportExtract,
  updateExtract,
} from "@/api/unit/extract";
import FileUpload from "@/components/FileUpload";
import { listUser } from "@/api/system/user";
import {
  listUnit,
  randomlist,
  getUnit,
  delUnit,
  addUnit,
  updateUnit,
  exportUnit,
  agentlist,
} from "@/api/unit/unit";
import { listUnittype, getUnittype } from "@/api/unit/unittype";
import { getRandomMsg, listRandom, DeleteMapping } from "@/api/unit/random";
import unitDetail from "@/common/unitDetail/unitDetail";
import DetailDialog from "@/common/detailDialog";

export default {
  name: "ExtractApprove",
  components: {
    FileUpload,
    unitDetail,
    DetailDialog,
  },
  data() {
    return {
      //控制资质列隐藏显示
      showmake: true,
      //默认同意
      radio: "0",
      // 上传文件的图片地址
      imgUrl: [],
      //打开预览
      innerVisible: false,
      // 遮罩层
      loading: true,
      //默认选中
      extractResident: "0",
      // 选中数组
      ids: [],
      //抽取人单位字典
      unitTypeponsonOptions: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目申请表格数据
      extractList: [],
      // 单位信息表格数据
      unitList: [],
      //招标招标人代表集合
      agentlist: [],
      // 单位类型字典
      unitTypeOptions: [],
      // 弹出层标题
      title: "",
      title1: "你的排除理由如下:",
      titlePrint: "",
      // 是否显示弹出层
      open: false,
      openPrint: false,
      unitopen: false,
      exclude: false,
      outframe: false,
      unitId: "",
      unittype: "",
      randomUnitName: "",
      dateTime: "",
      hour: new Date().getHours(),
      minute: new Date().getMinutes(),
      Random: {
        randomUnittypeId: null,
        randomBanRansom: null,
        randomUnitId: null,
        randomUnitName: null,
      },
      // 排除项目集合
      RandomList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        extractItem: null,
        extractUser: null,
        extractAddress: null,
        extractPrice: null,
        extractApproveStatus: null,
        maxPrice: null,
        randomUnittypeId: null,
        unitTypeId: null,
      },
      UnitqueryParams: {
        pageNum: 1,
        pageSize: 10,
        unitName: null,
        extractId: null,
        unitNaturalGrade: null,
        unitNaturalScope: null,
        unitType: null,
      },
      RandomqueryParams: {
        pageNum: 1,
        pageSize: 10,
        extractId: null,
        randomUnitId: null,
        annex: null,
      },
      // 表单参数
      form: {
        extractResident: "0",
      },
      //单位详情
      formUnit: {},
      // 表单校验
      rules: {
        extractUser: [
          { required: true, message: "抽取人不能为空", trigger: "blur" },
        ],
        createBy: [
          { required: true, message: "抽取单位不能为空", trigger: "blur" },
        ],
        extractItem: [
          { required: true, message: "项目名称不能为空", trigger: "blur" },
        ],
        randomUnittypeId: [
          { required: true, message: "抽取库不能为空", trigger: "change" },
        ],
      },
      unitName: "",
      unitsVisible: false
    };
  },
  created() {
    this.getList();
    listUnittype(this.unitTypeParams).then((response) => {
      this.unitTypeOptions = response.rows;
    });
    listUser().then((response) => {
      this.unitTypeponsonOptions = response.rows;
    });
  },
  methods: {
    //单位详情表单重置
    resetUnit() {
      this.formUnit = {
        unitId: null,
        unitSort: null,
        unitType: null,
        unitName: null,
        unitNaturalGrade: null,
        unitNaturalScope: null,
        unitAddress: null,
        unitRemarks: null,
      };
    },
    //为排除的单位添加颜色区分
    tableRowClassName({ row, rowIndex }) {
      if (row.unitStatues === 1) {
        return "denger-row";
      } else if (row.unitStatues === 2) {
        return "denger-row";
      } else if (row.unitStatues === 3) {
        return "denger-row";
      }
      return "";
    },
    //抽取人单位
    UnitTypeChangepenson(value) {
      /*listUser().then(response => {
				for(var o=0;o<response.rows.length;o++){
					if(value == response.rows[o].userId){
						this.queryParams.createBy = response.rows[o].nickName;
					}
				}
			});*/
    },
    /** 查询项目申请列表 */
    getList() {
      this.loading = true;
      this.queryParams.extractApproveStatus = "1,2,3";
      //这个参数是用来排除某个类别的单位   15为招标代理人库，需要排除掉，不做显示
      this.queryParams.unitTypeId = 15;
      listExtractPage(this.queryParams).then((response) => {
        this.extractList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //单位详情提交按钮
    submitFormUnit() {
      this.unitopen = false;
      this.resetUnit();
    },
    //单位详情
    unitShow(row) {
      const unitId = row.unitId || this.ids;
      getUnit(unitId).then((response) => {
        this.formUnit = response.data;
        this.unitopen = true;
        this.title = "单位详情";
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.RandomList = [];
      this.reset();
    },
    //单位详情取消按钮
    cancelUnit() {
      this.unitopen = false;
      this.resetUnit();
    },
    // 表单重置
    reset() {
      this.form = {
        extractId: null,
        extractItem: null,
        extractUser: null,
        extractRemarks: null,
        extractBanReason: null,
        extractScore: null,
        extractApproveStatus: "1",
        extractApproveIdea: null,
        randomUnittypeId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        extractResident: "0",
        RandomList: [],
        unitTypeName: null,
      };
      this.dateTime = null;
      this.resetForm("form");
    },
    // 排除状态翻译
    RandomTypeFormat(row) {
      if (row.unitStatues == 0) {
        return "正常";
      } else if (row.unitStatues == 1) {
        return "排除";
      } else if (row.unitStatues == 2) {
        return "扣分过多(排除)";
      } else if (row.unitStatues == 3) {
        return "已有进行中项目";
      } else if (row.randomBan == 4) {
        return "未中标";
      } else if (row.randomBan == 5) {
        return "废除报价";
      }
    },
    //单位选择select改变方法
    UnitTypeChange(value) {
      //让table显现出来

      //查询table数据
      this.UnitqueryParams.unitType = value;
      this.UnitqueryParams.extractId = this.form.extractId;
      //console.log('extractId' + this.UnitqueryParams.extractId);
      randomlist(this.UnitqueryParams).then((response) => {
        this.unitList = response.rows;
        this.loading = false;
      });
    },
    //手动排除翻译状态
    ManualApproveStatusFormat(row, column) {
      if (row.unitStatues == 0) {
        return "否";
      } else if (row.unitStatues == 1) {
        return "是";
      } else if (row.unitStatues == 2) {
        return "否";
      } else if (row.unitStatues == 3) {
        return "否";
      } else if (row.randomBan == 4) {
        return "未中标";
      } else if (row.randomBan == 5) {
        return "废除报价";
      }
    },
    //自动排除翻译状态
    AutomaticApproveStatusFormat(row, column) {
      if (row.unitStatues == 0) {
        return "否";
      } else if (row.unitStatues == 1) {
        return "否";
      } else if (row.unitStatues == 2) {
        return "是";
      } else if (row.unitStatues == 3) {
        return "是";
      } else if (row.randomBan == 4) {
        return "未中标";
      } else if (row.randomBan == 5) {
        return "废除报价";
      }
    },
    //转换单位库类型
    selecttypeLabel(datas, value) {
      var actions = [];
      Object.keys(datas).some((key) => {
        if (datas[key].unittypeId == "" + value) {
          actions.push(datas[key].unittypeName);
          return true;
        }
      });
      return actions.join("");
    },
    approveStatusFormat(row, column) {
      return this.getType(row, column);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.reset();
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.extractId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加项目申请";
    },
    // closeimgUrl(){
    // 	console.log(关闭);
    // },
    /** 审批按钮操作 */
    handleUpdate(row) {
      if (
        row.randomUnittypeId == 1 ||
        row.randomUnittypeId == 3 ||
        row.randomUnittypeId == 4 ||
        row.randomUnittypeId == 9
      ) {
        this.showmake = false;
      } else {
        this.showmake = true;
      }
      this.unittype = row.unitTypeId;
      this.reset();
      const extractId = row.extractId || this.ids;
      getExtract(extractId).then((response) => {
        this.form = response.data;
        this.form.unitTypeId = row.unitTypeId;
        this.imgUrl.push(response.data.extractSignUrl);
        this.UnitqueryParams.unitType = this.form.randomUnittypeId;
        this.UnitqueryParams.extractId = this.form.extractId;
        if(this.unittype == "15"){
          agentlist(this.UnitqueryParams).then((response) => {
            this.agentlist = response.rows;
            this.loading = false;
          });
        }else{
          randomlist(this.UnitqueryParams).then((response) => {
            this.unitList = response.rows;
            this.loading = false;
          });
        }
        
        if (this.radio === null) {
          this.radio = "0";
        } else if (this.radio == "1") {
          this.radio = "0";
        }
        for (let i of this.unitTypeOptions) {
          if (i.unittypeId == this.form.randomUnittypeId) {
            this.unitName = i.unittypeName;
            break;
          }
        }
        this.open = true;
        this.title = "审批项目申请";
      });
      //查询单位table数据
      // listRandom().then(response => {
      // 	for (var i = 0; i < response.rows.length; i++) {
      // 		this.unitList.push(response.rows[i]);
      // 	}
      // });
    },
    cancelImg() {
      this.imgUrl = [];
    },
    overcome(row) {
      this.unitId = row.unitId || this.ids;
      this.unittype = row.unitType || this.ids;
      this.unitName = row.unitName || this.ids;
      this.exclude = true;
      this.title = "排除单位";
    },
    // 保存排除理由
    excludeSave() {
      //创建一个排除实体类
      var RandomNew = {
        randomUnittypeId: null,
        randomBanRansom: null,
        randomUnitId: null,
        randomUnitName: null,
        extractId: null,
      };
      RandomNew.randomUnittypeId = this.unittype;
      RandomNew.randomUnitId = this.unitId;
      RandomNew.extractId = this.form.extractId;
      //表单区一样的名字
      RandomNew.randomBanRansom = this.form.randomBanRansom;
      RandomNew.randomUnitName = this.unitName;
      this.RandomList.push(RandomNew);
      this.exclude = false;
      //刷新单位库下的单位列表状态
      for (var i = 0; i < this.unitList.length; i++) {
        if (this.unitList[i].unitId == RandomNew.randomUnitId) {
          this.unitList[i].unitStatues = 1;
        }
      }
    },
    /**还原按钮*/
    DeleteMappingBtn(row) {
      var _this = this;
      const unitId = row.unitId || this.ids;
      //获取项目id
      this.RandomqueryParams.extractId = this.form.extractId;
      //获取单位id
      this.RandomqueryParams.randomUnitId = unitId;
      //console.log(this.RandomqueryParams.randomUnitId);
      this.$confirm("是否需要复原?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          //判断当前是否有存储好的排除数据
          //刷新单位库下的单位列表状态
          for (var i = 0; i < _this.unitList.length; i++) {
            if (_this.unitList[i].unitId == row.unitId) {
              _this.unitList[i].unitStatues = null;
            }
          }
          return DeleteMapping(_this.RandomqueryParams);
          for (var k = 0; k < _this.RandomList.length; k++) {
            if (_this.RandomList[k].unitStatues == 0) {
              _this.RandomList.splice(k, 1);
            }
          }
        })
        .then(() => {
          this.msgSuccess("还原成功");
          //刷新表格
          this.UnitqueryParams.unitType = this.form.randomUnittypeId;
          this.UnitqueryParams.extractId = this.form.extractId;
          //console.log('extractId' + this.UnitqueryParams.extractId);
          randomlist(this.UnitqueryParams).then((response) => {
            this.unitList = response.rows;
            this.loading = false;
          });
        }),
        () => {};
    },
    /** 提交按钮 */
    submitForm() {
      this.$confirm("确认提交审批吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$refs["form"].validate((valid) => {
            if (valid) {
              this.form.RandomList = this.RandomList;
              var json = {};
              for (var i = 0; i < this.form.RandomList.length; i++) {
                json[i] = this.form.RandomList[i];
              }
              JSON.stringify(json);
              //判断审批同意拒绝 返回状态码
              if (this.form.extractId != null) {
                if (this.radio == "0") {
                  this.form.extractApproveStatus = 2;
                } else if (this.radio == "1") {
                  this.form.extractApproveStatus = 0;
                }
                this.form.unitList = this.unitList;
                if (this.dateTime) {
                  this.form.sendMessageEndTime = this.dateTime;
                }
                updateExtract(this.form).then((response) => {
                  this.msgSuccess("审批完成");
                  this.open = false;
                  this.dateTime = null;
                  this.getList();
                });
                //排除
                if (JSON.stringify(json) == "{}") {
                  this.open = false;
                  this.getList();
                } else {
                  getRandomMsg(json).then((response) => {
                    this.open = false;
                    this.getList();
                  });
                }
              }
            } else {
              addExtract(this.form).then((response) => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          });
        })
        .catch((err) => {
          this.$message({
            type: "info",
            message: "已取消审批",
          });
        });
    },

    call() {
      this._data.exclude = false;
    },
    reason(row) {
      this.outframe = true;
      this.Random.randomUnitName = this.unitName;
      this.Random.randomUnittypeId = this.unittype;
      this.Random.randomUnitId = this.unitId;
    },
    determined() {
      this._data.outframe = false;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const extractIds = row.extractId || this.ids;
      this.$confirm(
        '是否确认删除项目申请编号为"' + extractIds + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delExtract(extractIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有项目申请数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportExtract(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
    viewUnits() {
      this.unitsVisible = true;
    },
    rowStyle({ row }) {
      let style = {};
      if (row.isTick == 0) style.backgroundColor = "#ffe4e1";
      return style;
    },
  },
};
</script>
<style type="text/css" scoped>
::v-deep .el-table .denger-row {
  background: #ffe4e1;
}
::v-deep .el-table .cell {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
::v-deep .el-table .cell:hover {
  white-space: normal;
}
.topbox {
  width: 100%;
}
.btobox {
  width: 100%;
}
.form-img-out {
  width: 130px;
  height: 130px;
}
.form-img-line {
  width: 500px;
  height: 500px;
}
.form-dialog {
  text-align: center;
}
.unitSort-box li {
  margin-top: 5px;
}
.el-form-item{
  margin-bottom: 0px !important;
}
</style>
